//
//  CustomPickerView.m
//  BrushFace
//
//  Created by 吕海瑞 on 15/12/28.
//  Copyright © 2015年 Zzz. All rights reserved.
//

#import "CustomPickerView.h"

@interface CustomPickerView ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property(nonatomic,strong)UIDatePicker *datePick;
@property(nonatomic,copy) NSString *resultString;
@end
@implementation CustomPickerView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
       
        _pickerView.delegate = self;
        _pickerView.dataSource = self;
    }
    return self;
}
-(void)awakeFromNib
{
    _pickerView.delegate = self;
    _pickerView.dataSource = self;

}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (_pickerStyle == Sexy)
    {
        _titleLable.text = @"改性别";
        return 3;
    }
    else if (_pickerStyle == EducationStatus)
    {
        _titleLable.text = @"";
        return 2;
    }
    else if (_pickerStyle == Education)
    {
        _titleLable.text = @"";
        return 2;
    }
    else if (_pickerStyle == HighEducation)
    {
        _titleLable.text = @"";
        return 6;
    }
    else
    {
         _titleLable.text = @"改年龄";
    return 5;
    }
    
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (_pickerStyle == Sexy)
    {
        NSArray *array = [[NSArray alloc]initWithObjects:@"男",@"女",@"其他",nil];
        return [array objectAtIndex:row];
    }
    else if (_pickerStyle == EducationStatus)
    {
        NSArray *array = [[NSArray alloc]initWithObjects:@"在读",@"毕业",nil];
        return [array objectAtIndex:row];

    }
    else if (_pickerStyle == Education)
    {
        NSArray *array = [[NSArray alloc]initWithObjects:@"在读",@"毕业",nil];
        return [array objectAtIndex:row];
    }
    else if (_pickerStyle == HighEducation)
    {
        NSArray *array = [[NSArray alloc]initWithObjects:@"高中以下",@"专科",@"本科",@"硕士",@"博士及以上",@"其他",nil];
        return [array objectAtIndex:row];

    }
        else
    {
        NSArray *array = [[NSArray alloc]initWithObjects:@"00",@"90",@"80",@"70",@"60",nil];
        return [array objectAtIndex:row];
    }
    
  
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (_pickerStyle == Sexy) {
        NSArray *array = [[NSArray alloc]initWithObjects:@"男",@"女",@"其他",nil];
        _resultString = [array objectAtIndex:row];
        
    }
    else if (_pickerStyle == EducationStatus)
    {
        NSArray *array = [[NSArray alloc]initWithObjects:@"在读",@"毕业",nil];
        _resultString = [array objectAtIndex:row];
    }
    else if (_pickerStyle == HighEducation)
    {
        NSArray *array = [[NSArray alloc]initWithObjects:@"高中以下",@"专科",@"本科",@"硕士",@"博士及以上",@"其他",nil];
       _resultString = [array objectAtIndex:row];
       

        
    }
    else if (_pickerStyle == Education)
    {
        NSArray *array = [[NSArray alloc]initWithObjects:@"高中以下",@"专科",@"本科",@"硕士",@"博士及以上",@"其他",nil];
        _resultString = [array objectAtIndex:row];
        
        
        
    }

    else
    {
     NSArray *array = [[NSArray alloc]initWithObjects:@"00",@"90",@"80",@"70",@"60",nil];
       _resultString = [array objectAtIndex:row];
        
    }
    
}

-(void)getResult:(result)result
{
    _resultStr = [result copy];
}
- (IBAction)cancelBtnClick:(id)sender {
    _cancelResult();
    [self removeFromSuperview];
}
- (IBAction)sureBtnClick:(id)sender
{
    if (_resultString.length>0)
    {
        _resultStr(_resultString);

    }
    else
    {
        if (_pickerStyle == Sexy)
        {
            NSArray *array = [[NSArray alloc]initWithObjects:@"男",@"女",@"其他",nil];
            
            NSString * str = [array objectAtIndex:[_pickerView selectedRowInComponent:0]];
            _resultStr(str);
            
            
            
            
        }
        else if (_pickerStyle == EducationStatus)
        {
            NSArray *array = [[NSArray alloc]initWithObjects:@"在读",@"毕业",nil];
            NSString * str = [array objectAtIndex:[_pickerView selectedRowInComponent:0]];
            _resultStr(str);
        }
        else if (_pickerStyle == HighEducation)
        {
            NSArray *array = [[NSArray alloc]initWithObjects:@"高中以下",@"专科",@"本科",@"硕士",@"博士及以上",@"其他",nil];
            NSString * str = [array objectAtIndex:[_pickerView selectedRowInComponent:0]];;
            _resultStr(str);
            
            
        }
        
        else
        {
            NSArray *array = [[NSArray alloc]initWithObjects:@"00",@"90",@"80",@"70",@"60",nil];
            
            NSString * str = [array objectAtIndex:[_pickerView selectedRowInComponent:0]];
            _resultStr(str);
            
        }

    
    
    }
        [self removeFromSuperview];
}
@end
